package com.bdqn.t296.noso.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.t296.noso.entity.ReportVo;
import com.bdqn.t296.noso.service.CTakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/caotake")
public class CTakeController {
    @Autowired
    private CTakeService cTakeService;

    //进入门诊取药页面
    @RequestMapping("/seltake")
    private Object seltake() {
        return "hospital/cquyao";
    }

    //模糊分页查询
    @RequestMapping("/selhuan")
    public Object selhuan(ReportVo reportVo, Model model, @RequestParam(required = false, defaultValue = "1") int current) {
        //creportService.upddang();
        Page<ReportVo> page = new Page<ReportVo>(current, 5);
        IPage<ReportVo> selhuan = cTakeService.selhuan(page, reportVo);
        System.out.println("当前记录： -----> ");
        model.addAttribute("report", selhuan);
        return "hospital/patientbank";
    }

    //查询所有患者信息
    @RequestMapping("/tselpreson")
    @ResponseBody
    public Object tselperson(int current) {
        //分页对象：查询获得 User 对象，查看第 1 页数据，每页显示 5 条记录
        Page<ReportVo> page = new Page<ReportVo>(current, 5);
        IPage<ReportVo> prescriPager = cTakeService.sel(page);
        return prescriPager;
    }

    //修改用户状态
    @RequestMapping("chuku")
    @ResponseBody
    public Object chuku(ReportVo reportVo) {
        Integer chuku = cTakeService.chuku(reportVo);
        return chuku;
    }
/*
    //进入查看患者页面
    @RequestMapping("haun")
    public Object haun() {

        return "cao/chuanzhe";
    }

    //查看患者信息
    @RequestMapping("selhuan")
    @ResponseBody
    public Object selhuan(ReportVo reportVo, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<ReportVo> selhuan = cTakeService.selhuan(reportVo);
        PageInfo pageInfo = new PageInfo(selhuan);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式，如果后台没有加上这句话的话需要在前台页面手动设置
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());
        return tableData;
    }

    //查看该用户的总价格
    @RequestMapping("zong")
    @ResponseBody
    public Object zong(Integer reid) {
        int zong = cTakeService.zong(reid);
        return zong;
    }*/
}
